package reviewAlgorithms.math;

public class ConvertToTitle {
    public static void main(String[] args) {
        int n = 701;
        System.out.println(convertToTitle(n));
        System.out.println(convertToTitle1(n));
    }
    public static String convertToTitle(int num) {
        StringBuilder stringBuilder = new StringBuilder();
        while (num / 26 > 0){
            num --;
            stringBuilder.append((char)(num % 26 + 'A'));
            num = num / 26;
        }
        if (num > 0){
            stringBuilder.append((char)(num - 1 + 'A'));
        }
        return stringBuilder.reverse().toString();
    }
    public static String convertToTitle1(int n) {
        if (n == 0) {
            return "";
        }
        n--;
        return convertToTitle1(n / 26) + (char) (n % 26 + 'A');
    }
}
